<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>login</title>
</head>
<body>
  <input id="username" type="text" />
  <input id="password" type="password" />
  <input id="submit" type="button" value="提交" />
  <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
  <script>
    document.getElementById('submit').addEventListener('click', function () {
      const username = document.getElementById('username').value;
      const password = document.getElementById('password').value;
      axios.post('/login', {username, password}, {
        xsrfCookieName: 'csrfToken',
        xsrfHeaderName: 'X-CSRF-Token'
      }).then(res => {
        if (res.status >= 200 && res.status < 300) {
          if (!res.data.errcode) {
            window.location.href = '/home';
          }
        }
      }).catch(err => err.response.status);
    });
  </script>
</body>
</html>